// pages/my_order/ser_order.js
var app=getApp()
var that
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    text: "This is page data.",
    currentTab: 0,
    isStatus: 'pay',
    orders:{},
    ordersn:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
    that.setData({ ordersn: options.ordersn});
    app.req("get_orderserver.html", { "openid": app.data.openid, "ordersn": options.ordersn }, function (res) {
      // console.log(res)
      if (res.status == "success") {
        res.mess.createtime1 = res.mess.createtime.substr(0, 10)
        res.mess.createtime2 = res.mess.createtime.substr(11, 5)
        if (res.mess.paytime!=0){
        res.mess.createtime3 = res.mess.paytime.substr(0, 10)
        res.mess.createtime4 = res.mess.paytime.substr(11, 5)
        }
        if (res.mess.fuwutime != 0) {
        res.mess.createtime5 = res.mess.fuwutime.substr(0, 10)
        res.mess.createtime6 = res.mess.fuwutime.substr(11, 5)
        }
        if (res.mess.endtime != 0) {
        res.mess.createtime7 = res.mess.endtime.substr(0, 10)
        res.mess.createtime8 = res.mess.endtime.substr(11, 5)
        }
        that.setData({ orders: res });
      } else if (res.status == "error") {
        app.toast(res.mess)
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.onLoad(options)
          }
        })
      }
    })
   
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winHeight: res.windowHeight,
          h: res.windowHeight
        });
      }
    });
  },
  cellphone: function () {
    wx.makePhoneCall({
      phoneNumber: app.hotelData.house_notict.phone //联系酒店的电话号码
    })
  },
  to_pay:function(){  //未付款时可点击  去支付
    app.req("repay_server.html", { "openid": app.data.openid, "ordersn": that.data.ordersn,'shop_id':wx.getStorageSync('shop_id') }, function (res) {
      if (res.status == "success") {
        wx.requestPayment(
          {
            'timeStamp': res.mess.timeStamp,
            'nonceStr': res.mess.nonceStr,
            'package': res.mess.package,
            'signType': res.mess.signType,
            'paySign': res.mess.paySign,
            'success': function (re) {
              app.toast("支付成功！")//设置状态
              that.data.orders.mess.status = 1
              that.setData({ orders: that.data.orders })
            },
            'fail': function (re) {
              app.modal("提示", "支付失败，半小时内未支付房费该订单将会被删除！", function (re) { })
              // app.toast("支付失败！")
            },
            'complete': function (res) { }
          })

      } else if (res.status == "error") {
        app.toast(res.mess)
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.to_pay()
          }
        })
      }
    })
  },
  giveup_adv:function(){  //点击取消预约
    app.req("refund.html", { "openid": app.data.openid, "ordersn": that.data.ordersn, "type": "server" }, function (res) {
      if (res.status == "success") {
        app.toast_up("退款中");
        // that.data.orders.mess.status = 6  //退款中
        // that.setData({ orders: that.data.orders })
      } else if (res.status == "error") {
        app.toast(res.mess)
      } else {
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.giveup_adv()
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  r_remark:function(e){
    // console.log(e.currentTarget.dataset.d)
    if (e.currentTarget.dataset.d){  //有留言才跳转
        wx.navigateTo({
          url: '../home/most_know?ser_remark=' + e.currentTarget.dataset.d,
        })
    }
  
  },
  //改变选项卡
  bindChange: function (e) {
    var that = this;
    //that.setData({ currentTab: e.detail.current });
  },
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current});
  },
  //选项卡标题绑定的事件
  swichNav: function (e) {
    var that = this;
    if (that.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      var current = e.target.dataset.current;
      that.setData({
        currentTab: parseInt(current),
      });
    };
  },
})